import { createApp } from 'vue';
import App from './App-simple.vue';
import router from './router';
import { createPinia } from 'pinia';

console.log('🚀 开始启动 Vue 应用...');

const app = createApp(App);
const pinia = createPinia();

app.use(router);
app.use(pinia);

console.log('📦 Vue 应用配置完成，准备挂载...');

// 简化的全局变量设置
if (typeof window !== 'undefined') {
  console.log('🌐 设置 Web 环境全局变量...');
  
  // 设置基本的全局变量
  (window as any).GLOBAL_DB = {
    books: new Map(),
    authors: new Map(),
    categories: new Map(),
    bookshelves: new Map(),
  };
  
  (window as any).GLOBAL_IPC = {
    on: (event: string, callback: Function) => console.log(`IPC.on: ${event}`),
    once: (event: string, callback: Function) => console.log(`IPC.once: ${event}`),
    send: (event: string, ...args: any[]) => console.log(`IPC.send: ${event}`, args),
    removeAllListeners: (event: string) => console.log(`IPC.removeAllListeners: ${event}`),
  };
  
  (window as any).GLOBAL_LOG = {
    info: (message: string) => console.log(`[INFO] ${message}`),
    error: (message: string) => console.error(`[ERROR] ${message}`),
    warn: (message: string) => console.warn(`[WARN] ${message}`),
    debug: (message: string) => console.debug(`[DEBUG] ${message}`),
  };
  
  (window as any).GLOBAL_PLUGINS = {
    list: [],
    get: (id: string) => null,
    install: (plugin: any) => console.log('Plugin install:', plugin),
    uninstall: (id: string) => console.log('Plugin uninstall:', id),
  };
  
  (window as any).GLOBAL_UPDATER = {
    check: () => Promise.resolve({ hasUpdate: false, version: '1.0.0' }),
    download: () => Promise.resolve(),
  };
  
  // 简化的 METADATA
  (window as any).METADATA = {
    name: 'ReadCat',
    version: '2.0.0',
    description: '开源免费的小说阅读器'
  };
  
  console.log('✅ 全局变量设置完成');
}

console.log('🎯 开始挂载 Vue 应用到 #app...');

try {
  app.mount('#app');
  console.log('🎉 Vue 应用挂载成功！');
} catch (error) {
  console.error('❌ Vue 应用挂载失败:', error);
}